#include <iostream>
#include <stdexcept>
#include "SDL.h"
#include "sdltimer.h"
using namespace std;

SDLTimer::SDLTimer()
{
       startTicks = 0;
       pausedTicks = 0;
       paused = false;
       started = false;
}

void SDLTimer::start()
{
       started = true;

       paused = false;

       startTicks = SDL_GetTicks();
}

void SDLTimer::stop()
{
       started = false;

       paused = false;
}

int SDLTimer::getTicks() const
{
       if(started == true)
       {
	      if(paused == true)
	      {
		     return pausedTicks;
	      }
	      else
	      {
		     return (SDL_GetTicks() - startTicks);
	      }
       }

       return 0;
}

void SDLTimer::pause()
{
       if(started == true && paused == false)
       {
	      paused = true;

	      pausedTicks = (SDL_GetTicks() - startTicks);
       }
}

void SDLTimer::unpause()
{
       if(paused == true)
       {
	      paused = false;

	      startTicks = (SDL_GetTicks() - pausedTicks);

	      pausedTicks = 0;
       }
}

bool SDLTimer::is_started() const
{
       return started;
}

bool SDLTimer::is_paused() const
{
       return paused;
}